﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using DBUtility;

namespace OracleDAL.DutyAssignment
{
    public class D_DutyBanci
    {
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM DUTY_ARRANGE_BANCI WHERE ");
            strSql.Append(strWhere);

            return OracleHelper.Exists(strSql.ToString());

        }

        /// <summary>
        ///  增加一条数据
        /// </summary>
        public bool Add(Model.DutyAssignment.M_DutyBanci model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("INSERT INTO DUTY_ARRANGE_BANCI(ID,DUTYID,NAME,REMARK,MOBANNAME,STARTTIME,ENDTIME,BANCI) ");
            strSql.Append(" VALUES(:ID,:DUTYID,:NAME,:REMARK,:MOBANNAME,:STARTTIME,:ENDTIME,:BANCI)");
            OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.VarChar,50),
					new OracleParameter(":DUTYID", OracleType.VarChar,50),
					new OracleParameter(":NAME", OracleType.VarChar,100),
					new OracleParameter(":REMARK", OracleType.VarChar,500),
					new OracleParameter(":MOBANNAME", OracleType.VarChar,100),
					new OracleParameter(":STARTTIME", OracleType.DateTime),
					new OracleParameter(":ENDTIME", OracleType.DateTime),
					new OracleParameter(":BANCI", OracleType.VarChar,2)};
            parameters[0].Value = model.ID;
            parameters[1].Value = model.DUTYID;
            parameters[2].Value = model.NAME;
            parameters[3].Value = model.REMARK;
            parameters[4].Value = model.MOBANNAME;
            parameters[5].Value = model.STARTTIME;
            parameters[6].Value = model.ENDTIME;
            parameters[7].Value = model.BANCI;

            return OracleHelper.ExecuteSql(strSql.ToString(), parameters) > 0 ? true : false;
        }

        /// <summary>
        ///  更新一条数据
        /// </summary>
        public bool Update(Model.DutyAssignment.M_DutyBanci model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("UPDATE DUTY_ARRANGE_BANCI SET DUTYID=:DUTYID,NAME =:NAME,REMARK=:REMARK,");
            strSql.Append(" MOBANNAME=:MOBANNAME,STARTTIME=:STARTTIME,ENDTIME=:ENDTIME,BANCI=:BANCI WHERE ID=:ID");
            OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.VarChar,50),
					new OracleParameter(":DUTYID", OracleType.VarChar,50),
					new OracleParameter(":NAME", OracleType.VarChar,100),
					new OracleParameter(":REMARK", OracleType.VarChar,500),
					new OracleParameter(":MOBANNAME", OracleType.VarChar,100),
					new OracleParameter(":STARTTIME", OracleType.DateTime),
					new OracleParameter(":ENDTIME", OracleType.DateTime),
					new OracleParameter(":BANCI", OracleType.VarChar,2)};
            parameters[0].Value = model.ID;
            parameters[1].Value = model.DUTYID;
            parameters[2].Value = model.NAME;
            parameters[3].Value = model.REMARK;
            parameters[4].Value = model.MOBANNAME;
            parameters[5].Value = model.STARTTIME;
            parameters[6].Value = model.ENDTIME;
            parameters[7].Value = model.BANCI;

            return OracleHelper.ExecuteSql(strSql.ToString(), parameters) > 0 ? true : false;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string ID)
        {
            string strSql = "DELETE FROM DUTY_ARRANGE_BANCI WHERE ID=:ID ";
            OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.VarChar,50)};
            parameters[0].Value = ID;

            return OracleHelper.ExecuteSql(strSql.ToString(), parameters) > 0 ? true : false;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.DutyAssignment.M_DutyBanci GetModel(string ID)
        {
            string strSql = "SELECT * FROM DUTY_ARRANGE_BANCI WHERE ID=:ID";
            OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.VarChar,50)};
            parameters[0].Value = ID;

            Model.DutyAssignment.M_DutyBanci model = new Model.DutyAssignment.M_DutyBanci();
            DataSet ds = OracleHelper.Query(strSql);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.ID = ds.Tables[0].Rows[0]["ID"].ToString();
                model.DUTYID = ds.Tables[0].Rows[0]["DUTYID"].ToString();
                model.NAME = ds.Tables[0].Rows[0]["NAME"].ToString();
                model.REMARK = ds.Tables[0].Rows[0]["REMARK"].ToString();
                model.MOBANNAME = ds.Tables[0].Rows[0]["MOBANNAME"].ToString();
                if (ds.Tables[0].Rows[0]["STARTTIME"].ToString() != "")
                {
                    model.STARTTIME = DateTime.Parse(ds.Tables[0].Rows[0]["STARTTIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ENDTIME"].ToString() != "")
                {
                    model.ENDTIME = DateTime.Parse(ds.Tables[0].Rows[0]["ENDTIME"].ToString());
                }
                model.BANCI = ds.Tables[0].Rows[0]["BANCI"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,DUTYID,NAME,REMARK,MOBANNAME,STARTTIME,ENDTIME,BANCI ");
            strSql.Append(" FROM DUTY_ARRANGE_BANCI ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return OracleHelper.Query(strSql.ToString());
        }

        #endregion  成员方法
    }
}
